// 云函数入口文件
const cloud = require('wx-server-sdk')
const nm = require('nodemailer')
var transporter = nm.createTransport({
  service:'163',
  port: 465,
  secure: true,
  auth:{
    user: '13531457409@163.com',
    pass: 'dajiayiqi123'
  }
});

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  if(event.operation=='report'){
    var mailOptions = await {
      to: 'nfu_community@163.com',
      from: '13531457409@163.com',
      subject: '用户举报',
      text: '被举报页面：' + event.pageID + '\n' + '举报原因：' + event.content.reportReason.join('-') + '-'+event.content.other+'\n'+'举报类型：'+event.type+'\n' +'举报人：'+event.reportor+'\n'+'被举报人：'+event.creator+'\n'+'被举报内容：'+event.description
    }
  }
  else if(event.operation=='suggestion'){
    var mailOptions = await {
      to: 'nfu_community@163.com',
      from: '13531457409@163.com',
      subject: '用户反馈',
      text: '反馈用户：' + event.openid + '\n' + '反馈内容：' + event.content.ui.join('-') + '\n' + event.content.functions.join('-') + '\n' + event.content.community.join('-') + '\n' + event.content.other + '\n' + '图片：' +event.figureID.join('\n')
    }
  }
  const info = await transporter.sendMail(mailOptions)
  return info
}